<template>
  <div id="postTopSearch">
    <h1 class="con-right-title">
      岗位管理
    </h1>
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        :rules="rules"
        class="demo-form-inline"
      >
        <el-form-item label="岗位编码" prop="postCode">
          <el-input
            v-model="formInline.postCode"
            placeholder="请输入关键词搜索"
          ></el-input>
        </el-form-item>
        <el-form-item label="岗位名称" prop="postName">
          <el-input
            v-model="formInline.postName"
            placeholder="请输入关键词搜索"
          ></el-input>
        </el-form-item>
        <el-form-item label="岗位状态" prop="status">
          <el-select v-model="formInline.status" placeholder="请选择岗位状态">
            <el-option
              v-for="item in statusList"
              :key="item.dictLabel"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
export default {
  name: 'PostTopSearch',
  msg: '岗位管理-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          postName: '', // 岗位名称
          postCode: '', // 岗位编码
          status: '' // 岗位状态,默认所有
        }
      }
    }
  },
  data() {
    return {
      statusList: [
        // 用户状态
        { dictLabel: '所有', dictValue: '' }
      ],
      rules: {
        postName: {},
        postCode: {},
        status: {}
      }
    }
  },
  mounted() {
    this.getStatusList()
  },
  methods: {
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
    },
    /* 获取岗位状态 */
    async getStatusList() {
      let data = await sysNormalDisable('sys_normal_disable','sysNormalDisable')
      this.statusList = this.statusList.concat(data)
    }
  }
}
</script>

<style lang="less"></style>
